package com.youlian.manager.service;

import com.youlian.common.Constants;
import com.youlian.manager.api.CardAPI;
import com.youlian.manager.model.CardDetParentsResult;
import com.youlian.manager.model.CardParentsResult;
import com.youlian.manager.model.CardStoreDetParentsResult;
import com.youlian.manager.param.CardDetailedParam;
import com.youlian.manager.param.CardsParam;
import com.youlian.utils.JsonUtils;


public class CardService extends BaseService{
	
	private CardAPI api;
	
	/**
	 * 首页数据
	 *
	 * @return
	 * @throws Exception
	 */
	public CardParentsResult getCards(String user_token, int channe_id) throws Exception {

		CardParentsResult result = null;

		api = new CardAPI();
		CardsParam param = new CardsParam();

		param.setService(Constants.youlian_cards_get);
		param.setUser_token(user_token);
		param.setChannel_id(channe_id);

		jsonData = api.getCards(param);
		System.out.println("jsonData:"+jsonData);
			result = (CardParentsResult) JsonUtils.parseJson2Obj(jsonData, CardParentsResult.class);
         
		return result;
	}
	
	/**
	 * 会员卡详情
	 *
	 * @return
	 * @throws Exception
	 */
	public CardDetParentsResult getCardDet(String card_id) throws Exception {

		CardDetParentsResult result = null;

		api = new CardAPI();
		CardDetailedParam param = new CardDetailedParam();

		param.setService(Constants.youlian_card_det_get);
		param.setCard_id(card_id);

		jsonData = api.getCardDet(param);
		System.out.println("jsonData:"+jsonData);
			result = (CardDetParentsResult) JsonUtils.parseJson2Obj(jsonData, CardDetParentsResult.class);
         
		return result;
	}

	/**
	 * 商家详情
	 *
	 * @return
	 * @throws Exception
	 */
	public CardStoreDetParentsResult getStoreDet(String card_id) throws Exception {

		CardStoreDetParentsResult result = null;

		api = new CardAPI();
		CardDetailedParam param = new CardDetailedParam();

		param.setService(Constants.youlian_store_det_get);
		param.setCard_id(card_id);

		jsonData = api.getStoreDet(param);
		System.out.println("jsonData:"+jsonData);
			result = (CardStoreDetParentsResult) JsonUtils.parseJson2Obj(jsonData, CardStoreDetParentsResult.class);
         
		return result;
	}
}
